﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoderJoe.WoW.Services;

namespace CoderJoe.WoW.GearManager
{
	public class CharacterModel
		: Model
	{
		public string Name
		{
			get { return GetValue("Name", String.Empty); }
			set { SetValue("Name", value); }
		}

		public string BattleGroup
		{
			get { return GetValue("BattleGroup", String.Empty); }
			set { SetValue("BattleGroup", value); }
		}
		public string CharacterClass
		{
			get { return GetValue("CharacterClass", String.Empty); }
			set { SetValue("CharacterClass", value); }
		}
		public IEnumerable<CharacterItemModel> Items
		{
			get { return GetValue<IEnumerable<CharacterItemModel>>("Items", null); }
		}

		public string Realm
		{
			get { return GetValue("Realm", String.Empty); }
			set { SetValue("Realm", value); }
		}

		protected List<CharacterItemModel> ItemList { get; set; }

		public CharacterModel()
			: base()
		{
			ItemList = new List<CharacterItemModel>(19);
			for (int i = 0; i < 19; i++)
			{
				ItemList.Add(new CharacterItemModel() { SlotIndex = i });
			}
			SetValue("Items", ItemList);
		}

		public void LoadModel(Character character)
		{
			Name = character.Name;
			Realm = character.Realm;
			BattleGroup = character.BattleGroup;
			CharacterClass = character.CharacterClass;

			for (int i = 0; i < character.Items.Length; i++)
			{
				CharacterItemModel model = ItemList[i];
				model.LoadModel(character.Items[i]);
			}
		}
	}
}
